package com.lk.controller;

import com.lk.service.impl.HelloService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * author lk
 *
 * @date 2021/10/27 13:50
 * @description TODO
 * @since 1.0
 */
@RestController
public class HelloController {

    @Resource
    private HelloService helloService;

    @PreAuthorize("hasAnyAuthority('user:add')")
    @GetMapping("/hello")
    public String  hello() {
        helloService.hello();
        return "success";
    }

    @GetMapping("/test")
    public Authentication  test(Authentication authentication) {
      return SecurityContextHolder.getContext().getAuthentication();
    }
}
